
export function pieChartAniFun(echartData, chartsId) {
  var colorList = ["#CC1507", "#56B6F8", "#469F04", "#FABE33"];
  let option2
  var seriesData = echartData.map((item, index) => {
    return {
      ...item,
      actValue: item.count,
      label: {
        show: true,
        position: "outside",
        borderRadius: 5,
        padding: [0, 5, 3, -3],
        color: '#fff',
        textStyle: {
          fontSize: 14,
        },
        formatter: function (optionsData) {
          return (
            "{name|" +optionsData.name +"}\n" +
            " {count|" + optionsData.percent.toFixed(0) +"%}"
          )
        },
        rich: {
          name: {
            fontSize: 14,
            color: "#ffffff",
            padding: [-40, 0, 0, 0],
          },
          value: {
            fontSize: 14,
            color: colorList[index],
            padding: [-20, 0, 0, 0],
          },
        },
      },
    };
  });
  let option = getPie3D(seriesData, 0);// 可做为调整内环大小 0为实心圆饼图，大于0 小于1 为圆环
  // 生成扇形的曲面参数方程，用于 series-surface.parametricEquation
  function getParametricEquation(startRatio, endRatio, isSelected, isHovered, k, h) {
    const midRatio = (startRatio + endRatio) / 2;
    const startRadian = startRatio * Math.PI * 2;
    const endRadian = endRatio * Math.PI * 2;
    const midRadian = midRatio * Math.PI * 2;
    // 如果只有一个扇形，则不实现选中效果。
    if (startRatio === 0 && endRatio === 1) {
      isSelected = false;
    }
    k = typeof k !== 'undefined' ? k : 1 / 3;
    const offsetX = isSelected ? Math.cos(midRadian) * 0.1 : 0;
    const offsetY = isSelected ? Math.sin(midRadian) * 0.1 : 0;
    // 鼠标滑过时外环放大大小
    const hoverRate = isHovered ? 1.05 : 1;
    // 返回曲面参数方程
    return {
      u: {
        min: -Math.PI,
        max: Math.PI * 3,
        step: Math.PI / 32,
      },

      v: {
        min: 0,
        max: Math.PI * 2,
        step: Math.PI / 20,
      },

      x: function (u, v) {
        if (u < startRadian) {
          return offsetX + Math.cos(startRadian) * (1 + Math.cos(v) * k) * hoverRate;
        }
        if (u > endRadian) {
          return offsetX + Math.cos(endRadian) * (1 + Math.cos(v) * k) * hoverRate;
        }
        return offsetX + Math.cos(u) * (1 + Math.cos(v) * k) * hoverRate;
      },

      y: function (u, v) {
        if (u < startRadian) {
          return offsetY + Math.sin(startRadian) * (1 + Math.cos(v) * k) * hoverRate;
        }
        if (u > endRadian) {
          return offsetY + Math.sin(endRadian) * (1 + Math.cos(v) * k) * hoverRate;
        }
        return offsetY + Math.sin(u) * (1 + Math.cos(v) * k) * hoverRate;
      },

      z: function (u, v) {
        if (u < -Math.PI * 0.5) {
          return Math.sin(u);
        }
        if (u > Math.PI * 2.5) {
          return Math.sin(u);
        }
        return Math.sin(v) > 0 ? 60 : -1;
      },
    };
  }
  // 生成模拟 3D 饼图的配置项
  function getPie3D(pieData, internalDiameterRatio) {
    const series = [];
    let sumValue = 0;
    let startValue = 0;
    let endValue = 0;
    const legendData = [];
    const k =
      typeof internalDiameterRatio !== 'undefined'
        ? (1 - internalDiameterRatio) / (1 + internalDiameterRatio)
        : 1 / 3;
    for (let i = 0; i < pieData.length; i += 1) {
      sumValue += pieData[i].count;
      const seriesItem = {
        name: typeof pieData[i].name === 'undefined' ? `series${i}` : pieData[i].name,
        type: 'surface',
        parametric: true,
        wireframe: {
          show: false,
        },
        pieData: pieData[i],
        pieStatus: {
          selected: false,
          hovered: false,
          k,
        },
      };
      if (typeof pieData[i].itemStyle !== 'undefined') {
        const { itemStyle } = pieData[i];
        // eslint-disable-next-line no-unused-expressions
        typeof pieData[i].itemStyle.color !== 'undefined' ? (itemStyle.color = pieData[i].itemStyle.color) : null;
        // eslint-disable-next-line no-unused-expressions
        typeof pieData[i].itemStyle.opacity !== 'undefined'
          ? (itemStyle.opacity = pieData[i].itemStyle.opacity)
          : null;

        seriesItem.itemStyle = itemStyle;
      }
      series.push(seriesItem);
    }
    for (let i = 0; i < series.length; i += 1) {
      endValue = startValue + series[i].pieData.count;
      series[i].pieData.startRatio = startValue / sumValue;
      series[i].pieData.endRatio = endValue / sumValue;
      series[i].parametricEquation = getParametricEquation(
        series[i].pieData.startRatio,
        series[i].pieData.endRatio,
        true,
        false,
        k,
        10//在此处传入饼图初始高度h
      );
      startValue = endValue;
      legendData.push(series[i].name);
    }

    series.push({
      name: 'pie2d',
      type: 'pie',
      label: {
        color: '#ffffff',
        opacity: 1,
        fontStyle: 'normal',
        fontSize: 12,
        fontFamily: 'Microsoft YaHei',
        formatter: (params) => {
          return `${params.data.name}\n${params.data.count}\n${((params.data.count / _.sumBy(pieData, 'count')) * 100).toFixed(2)}%`
        }
      },
      labelLine: {
        length: 20,
      },
      startAngle: -30, //起始角度，支持范围[0, 360]。
      clockwise: false, //饼图的扇区是否是顺时针排布。上述这两项配置主要是为了对齐3d的样式
      radius: ['50%', '75%'],
      center: ['50%', '65%'],
      data: pieData,
      itemStyle: {
        opacity: 0,
      },
    });

    // 准备待返回的配置项，把准备好的series 传入。
    option2 = {
      title: {
        show: false,
      },
      color: colorList,
      tooltip: {
        formatter: (params) => {
          if (params.seriesName !== 'mouseoutSeries') {
            return `${params.marker}${params.seriesName}：${pieData[params.seriesIndex].count}`;
          }
          return '';
        },
      },
      
      xAxis3D: {
        min: -1,
        max: 1,
      },
      yAxis3D: {
        min: -1,
        max: 1,
      },
      zAxis3D: {
        min: -1,
        max: 1,
      },
      grid3D: {
        show: false,
        top: '5%',
        boxHeight: 1,//修改立体饼图的高度
        viewControl: {
          // 3d效果可以放大、旋转等，
          alpha: 30,//饼图翻转的程度
          beta: 30,
          rotateSensitivity: 1,
          zoomSensitivity: 0,
          panSensitivity: 0,
          autoRotate: false,//是否自动旋转
          distance: 280,//距离越小看到的饼图越大
        },

      },
      series,
    };
    // lineAreaCharts.setOption(option2, true);
  }
  return option2
}


